﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace LibRTC.Core
{
    /// <summary>
    /// Class use to keep some system variables
    /// </summary>
    public class RTCSystem
    {
        private static RTCSystem _instance = null; 

        //private static string _sipServerName = "vcedu.3322.org";
        //private static string _sipServerIp = "166.111.134.27";
        //private static string _sipRealm = "vcedu.3322.org";

        #region Configuration

        private static string _sipServerName = "192.168.0.150";
        private static string _sipServerIp = "192.168.0.150";
        private static string _sipRealm = "192.168.0.150";

        private static int _sipAuth = RTCConst.RTCAU_DIGEST;
        private static int _sipTransport = RTCConst.RTCTR_UDP;
        //private static int _sipTransport = RTCConst.RTCTR_TCP;

        // no one can instantiate it
        private RTCSystem()
        {
            _instance = this;
        }

        /// <summary>
        /// We make this class singleton
        /// </summary>
        /// <returns>instance of RTCSystem</returns>
        public static RTCSystem GetInstance()
        {
            if(null == _instance)
            {
                _instance = new RTCSystem();
            }

            return _instance;
        }

        public string GetSipServerName()
        {
            return _sipServerName;
        }

        public void SetSipServerName(string sipServerName)
        {
            _sipServerName = sipServerName;
        }

        public string GetSipServerIp()
        {
            return _sipServerIp;
        }

        public void SetSipServerIp(string sipServerIp)
        {
            _sipServerIp = sipServerIp;
        }

        public string GetSipRealm()
        {
            return _sipRealm;
        }

        public void SetSipRealm(string sipRealm)
        {
            _sipRealm = sipRealm;
        }

        public string GetUserURI(string username)
        {
            return "sip:" + username + "@" + GetSipServerIp();
        }

        public int GetSipAuth()
        {
            return _sipAuth;
        }

        public int GetSipTransport()
        {
            return _sipTransport;
        }

        public string GetSipTransportString() {
            if( RTCConst.RTCTR_TCP == _sipTransport) {
                return "TCP";
            }
            else if (RTCConst.RTCTR_UDP == _sipTransport) {
                return "UDP";
            }
            else {
                return "TLS";
            }
        }

        #endregion //Configuration

        #region Local Info

        private string _localUserName = string.Empty;
        private string _localUserPassword = string.Empty;

        public string LocalUserName {
            get {
                return _localUserName;
            }
            set {
                Debug.Assert(null != value);
                _localUserName = value;
            }

        }

        public string LocalUserPassword {
            get {
                return _localUserPassword;
            }
            set {
                Debug.Assert(null != value);
                _localUserPassword = value;
            }
        }

        public string LocalUserURI {
            get {
                Debug.Assert(null != _localUserName);
                Debug.Assert(!string.Empty.Equals(_localUserName));
                return GetUserURI(_localUserName);
            }
        }

        #endregion Local Info

    }
}